﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FortuneHeaven.Web.Common;
using FortuneHeavenBAL;
using FortuneHeavenCommon.DataMap;
using FortuneHeavenCommon.ComMethod;

namespace FortuneHeaven.Web.Pages.UserCenter
{
    public partial class SetNewPassword : BasePage
    {
        public int userid = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            int.TryParse(Request["userid"], out userid);
            if (!IsPostBack)
            {
                SetPageHeader(FortuneHeavenCommon.Enum.MainPageTabType.hidden);
                UserInforBO bo = new UserInforBO();
                UserInfor infor = bo.GetUserInfor(userid);
                if (infor != null)
                {
                    ltQuestion.Text = infor.RegisterQuestion;
                }
                else
                {
                    ltQuestion.Text = "";
                }
            }
        }

        public void ResetPassword(object sender, EventArgs e)
        {
            UserInforBO bo = new UserInforBO();
            UserInfor infor = bo.GetUserInfor(userid);
            AccountsInfoBO acountinfo = new AccountsInfoBO();
            if (infor!=null&&!string.IsNullOrEmpty(infor.RegisterQuestion))
            {
                if (infor.RegisterAnswer == this.txtAnswer.Text.Trim())
                {
                    if (txtNewPassword.Text != txtReinput.Text)
                    {
                        ShowCurError("两次密码输入不一致");
                    }
                    else
                    {
                        if (this.txtNewPassword.Text.Length < 6 || this.txtNewPassword.Text.Length > 15)
                        {
                            ShowCurError("新密码必须由6-15位数字或字母组成");
                        }
                        else
                        {
                            acountinfo.SetNewPassword(userid, CommonEncrypt.ClientEncrypt(this.txtAnswer.Text));
                            Response.Redirect(Page.ResolveUrl("~/Pages/UserCenter/ResetSuccess.aspx"));
                        }
                    }
                }
                else
                {
                    ShowCurError("答案错误");
                }
            }
            else
            {
                ShowCurError("该帐号未设置信息用于找回密码");
            }
            //bo.SetNewPassword
        }
    }
}